﻿<UserControl x:Class="TorchView.PakViewer.PakView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:TorchView.PakViewer"
             xmlns:zip="clr-namespace:TorchView.PakViewer.Zip"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <local:ZipConverter x:Key="ZipConverter" />
        <local:IsNullConverter x:Key="IsNullConverter" />
        <local:ImageConverter x:Key="ImageConverter" />
    </UserControl.Resources>

    <Border CornerRadius="2" Background="#20FFFFFF" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition Width="2*"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <TreeView ItemsSource="{Binding FileRoot}" Grid.Column="0" HorizontalAlignment="Left" Name="FileView" VerticalAlignment="Top">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate DataType="{x:Type zip:ZipNode}" ItemsSource="{Binding Children}" >
                        <TextBlock Text="{Binding Name}"/>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
            
            <GridSplitter Background="Red" Grid.Column="1" Grid.Row="0" Height="Auto" Width="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
            <Grid Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
   
                <TextBox Text="{Binding ElementName=FileView, Path=SelectedItem.Path, Mode=OneWay}"/>
                <TreeView Grid.Row="1" ItemsSource="{Binding ElementName=FileView, Path=SelectedItem, Mode=OneWay, Converter={StaticResource ZipConverter}}" HorizontalAlignment="Left" Name="DatView" VerticalAlignment="Top">
                    <TreeView.ItemTemplate>
                        <HierarchicalDataTemplate DataType="{x:Type local:DataViewModel}" ItemsSource="{Binding SubBlocks}" >
                            <TextBlock Text="{Binding Name}"/>
                        </HierarchicalDataTemplate>
                    </TreeView.ItemTemplate>
                    <TreeView.Style>
                        <Style TargetType="{x:Type TreeView}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=DatView, Path=ItemsSource, Mode=OneWay, Converter={StaticResource IsNullConverter}}" Value="true">
                                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ElementName=DatView, Path=ItemsSource, Mode=OneWay, Converter={StaticResource IsNullConverter}}" Value="false">
                                    <Setter Property="Visibility" Value="Visible"></Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TreeView.Style>
                </TreeView>
                <Image Source="{Binding ElementName=FileView, Path=SelectedItem, Mode=OneWay, Converter={StaticResource ImageConverter}}" />
            </Grid>
        </Grid>
    </Border>
</UserControl>
